//
//  PopView.m
//  CustomerService_Lee
//
//  Created by MrLee on 2017/6/9.
//  Copyright © 2017年 MrLee.com. All rights reserved.
//

#define SWIDTH [UIScreen mainScreen].bounds.size.width
#define SHIGHT [UIScreen mainScreen].bounds.size.height

#import "PopView.h"
#import "StarSliderView.h"
#import "YYTextView.h"
#import "GKCover.h"


@interface PopView ()<StarSLiderDelegate>

@end

@implementation PopView

#pragma mark -------加载xib
+(instancetype)allocPop
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

-(void)awakeFromNib
{

    [super awakeFromNib];
    
    [self initSubViews];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [self setFrame];
    
}

#pragma mark -------初始化子视图
-(void)initSubViews
{

    _star = [[StarSliderView alloc]initWithFrame:CGRectMake(0, 0, SWIDTH/2, _starV.frame.size.height) andWithCurrentStarNum:5 andUserEnabled:YES andWithDistance:10];
    _textV = [[YYTextView alloc]init];
    
    _star.delegate = self;
    
    [_starV addSubview:_star];
    _textV.font = [UIFont systemFontOfSize:17];
    _textV.placeholderFont = [UIFont systemFontOfSize:17];
    _textV.layer.cornerRadius = 6;
    _textV.layer.masksToBounds = YES;
    
    _textV.backgroundColor = [UIColor whiteColor];
    _textV.placeholderText = @"请输入您的建议...";
    
    [_inputV addSubview:_textV];
    
    self.layer.cornerRadius = 6;
    
    self.layer.masksToBounds = YES;
}

#pragma mark -------设置子视图位置
-(void)setFrame{
    
    _star.frame = CGRectMake((_starV.frame.size.width-_star.frame.size.width)/2, 0, SWIDTH/2,_starV.frame.size.height);

    _textV.frame = CGRectMake(0, 0, _inputV.frame.size.width,_inputV.frame.size.height);

}

#pragma mark -------星星代理方法
-(void)starSliderMoveWithCurrentNum:(int)starNum{
    
    NSLog(@"------星星有%d颗-----",starNum);
}

#pragma mark -------是否匿名评价
- (IBAction)selectName:(UIButton *)sender {
    
    sender.selected = !sender.selected;
}

#pragma mark -------取消评价
- (IBAction)cancelBtn:(UIButton *)sender {
    
    [GKCover hideView];
}

#pragma mark -------提交评价
- (IBAction)submitBtn:(UIButton *)sender {
    
    if (_textV.text.length == 0) {
        
        [MXUtility showTips:@"评论内容不能为空哦"];
    }else{
    
        if (_nameBtn.selected) {
            
            _submitBlock(@"1");
            
        }else{
            
            _submitBlock(@"0");
        
        }
        
    }
    
}

@end
